﻿<uwpcControls:UniversalPage x:Name="Root"
      x:Class="UWPCore.Framework.Controls.AppShell"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:controls="using:UWPCore.Framework.Controls"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:uwpcControls="using:UWPCore.Framework.Controls"
      xmlns:uwpcConverters="using:UWPCore.Framework.Converters"                           
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
      KeyDown="AppShell_KeyDown"
      TabNavigation="Cycle"
      mc:Ignorable="d">

    <!-- Using a Page as the root for the app provides a design time experience as well as ensures that
         when it runs on Mobile the app content won't appear under the system's StatusBar which is visible 
         by default with a transparent background.  It will also take into account the presence of software
         navigation buttons if they appear on a device.  An app can opt-out by switching to UseCoreWindow.
    -->

    <Page.Resources>
        <uwpcConverters:BooleanToNullableConverter x:Key="boolToNullableConv" />

        <DataTemplate x:Key="NavMenuItemTemplate" x:DataType="controls:NavMenuItem">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="48" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <!-- Showing a ToolTip and the Label is redundant.  We put the ToolTip on the icon.
                     It appears when the user hovers over the icon, but not the label which provides
                     value when the SplitView is 'Compact' while reducing the likelihood of showing
                     redundant information when the label is shown.-->
                <FontIcon x:Name="Glyph" FontSize="16" Glyph="{x:Bind SymbolChar}" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTipService.ToolTip="{x:Bind Label}"/>
                <TextBlock x:Name="Text" Grid.Column="1" Text="{x:Bind Label}" />
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <Grid>
        <!-- Adaptive triggers -->
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="720" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="RootSplitView.DisplayMode" Value="CompactInline"/>
                        <!--<Setter Target="RootSplitView.IsSwipeablePaneOpen" Value="False"/> Could cause a crash in RELEASE mode -->
                    </VisualState.Setters>
                </VisualState>
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="RootSplitView.DisplayMode" Value="Overlay"/>
                        <!--<Setter Target="RootSplitView.IsSwipeablePaneOpen" Value="False"/> Could cause a crash in RELEASE mode -->
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <!-- Top-level navigation menu + app content -->
        <uwpcControls:SwipeableSplitView x:Name="RootSplitView"
                   DisplayMode="Inline"
                   OpenPaneLength="256"
                   IsTabStop="False">
            <SplitView.Pane>
                <!-- A custom ListView to display the items in the pane.  The automation Name is set in the ContainerContentChanging event. -->
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Rectangle x:Name="HamburgerButtonBackground" Height="48" HorizontalAlignment="Stretch" VerticalAlignment="Top" Fill="Transparent" />

                    <controls:NavMenuListView x:Name="NavMenuList" Grid.Row="0"
                                          TabIndex="3"
                                          Margin="0,48,0,0"
                                          ContainerContentChanging="NavMenuItemContainerContentChanging"
                                          ItemContainerStyle="{StaticResource NavMenuItemContainerStyle}"
                                          ItemTemplate="{StaticResource NavMenuItemTemplate}"
                                          ItemInvoked="NavMenuList_ItemInvoked"
                                          VerticalAlignment="Top"
                                          ScrollViewer.VerticalScrollMode="Auto"
                                          ScrollViewer.VerticalScrollBarVisibility="Hidden">
                    </controls:NavMenuListView>


                    <StackPanel Grid.Row="1">
                        <Rectangle x:Name="NavMenuSeperator" Height="1" Fill="{StaticResource SystemControlHighlightListLowBrush}" />

                        <controls:NavMenuListView x:Name="NavMenuListBottomDock"
                                          TabIndex="3"
                                          ContainerContentChanging="NavMenuItemContainerContentChanging"
                                          ItemContainerStyle="{StaticResource NavMenuItemContainerStyle}"
                                          ItemTemplate="{StaticResource NavMenuItemTemplate}"
                                          ItemInvoked="NavMenuList_ItemInvoked"
                                          ScrollViewer.VerticalScrollMode="Disabled"
                                          ScrollViewer.VerticalScrollBarVisibility="Hidden">
                        </controls:NavMenuListView>
                    </StackPanel>

                </Grid>
            </SplitView.Pane>

            <!-- Content is added at startup in code... -->

        </uwpcControls:SwipeableSplitView>

        <!-- DEBUG OUTPUT FOR AppShell/SwipableSplitView -->
        <!--<StackPanel>
            <TextBlock Text="{Binding ElementName=RootSplitView, Path=IsSwipeablePaneOpen, Converter={StaticResource boolToNullableConv}}" />
        </StackPanel>-->

        <!-- Declared last to have it rendered above everything else, but it needs to be the first item in the tab sequence. -->
        <ToggleButton x:Name="TogglePaneButton"
                      x:Uid="AppShellMenu"
                      TabIndex="1"
                      Style="{StaticResource SplitViewTogglePaneButtonStyle}"
                      IsChecked="{x:Bind RootSplitView.IsSwipeablePaneOpen, Mode=TwoWay, Converter={StaticResource boolToNullableConv}}"
                      Unchecked="TogglePaneButton_Unchecked"
                      Checked="TogglePaneButton_Checked"
                      AutomationProperties.Name="Menu"
                      ToolTipService.ToolTip="Menu"/>
    </Grid>
</uwpcControls:UniversalPage>
